﻿<%@ Page Title="Xtablish CRM / Users" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Users.aspx.cs" Inherits="Web.Account.Users" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Con1" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function setSelectedIndex(combo) {
                combo.trackChanges();
                combo.get_items().getItem(0).select();
                combo.updateClientState();
                combo.commitChanges();
            }

            function ClearClick() {
                document.getElementById('<%= txtUserName.ClientID %>').value = "";
                document.getElementById('<%= txtEmail.ClientID %>').value = "";
                document.getElementById('<%= txtPhone.ClientID %>').value = "";
                var atcombo = $find("<%= ddlRole.ClientID %>");
                setSelectedIndex(atcombo);
                $find("<%= RadButton3.ClientID %>").set_checked(true);
            }
            function isPressEnter(evt) {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode == 13) {
                    var clickButton = document.getElementById('<%= btnSearch.ClientID %>');
                    clickButton.click();
                }
            }

            function OnClientClose(oWnd, args) {
            }
            function RowMouseOver(sender, eventArgs) {
                index = eventArgs.get_itemIndexHierarchical();
            }
            function openRadwindow(url, formname) {
                var grid = $find("<%= RadGrid1.ClientID %>");
                var masterTableView = grid.get_masterTableView();
                var rbtnPercent, divDiscountPercent, divDiscountPrice;
                var row = masterTableView.get_dataItems()[index];
                var userID = row.getDataKeyValue("UserID");
                openWin(url + userID, formname);
                return false;
            }
            
        </script>
    </telerik:RadCodeBlock>
    <div class="register">
        <div class="container-fluid">
            <div class="panel-group" id="accordion" runat="server" role="tablist" aria-multiselectable="true">
                <div class="row">
                    <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingOne">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">Search <i class="glyphicon glyphicon-circle-arrow-down" style="display: none;"></i><i class="glyphicon glyphicon-circle-arrow-up"></i>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
                            <div class="panel-body">
                                <div class="firstrow">
                                    <div class="edit-form">
                                        <div class="control-group">
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">User Name </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <asp:TextBox ID="txtUserName" runat="server" class="form-control" onkeypress="isPressEnter(event)" />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Office Phone </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <asp:TextBox ID="txtPhone" runat="server" class="form-control" onkeypress="isPressEnter(event)" />
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Admin</label>
                                                </div>
                                                <div class="col-md-8 checkbox-control">
                                                    <div class="controls">
                                                        <telerik:RadButton ID="RadButton1" runat="server" ToggleType="Radio" ButtonType="ToggleButton"
                                                            GroupName="Radios" AutoPostBack="false" CausesValidation="false" Text="Yes">
                                                        </telerik:RadButton>
                                                        <telerik:RadButton ID="RadButton2" runat="server" ToggleType="Radio" ButtonType="ToggleButton"
                                                            GroupName="Radios" AutoPostBack="false" CausesValidation="false" Text="No">
                                                        </telerik:RadButton>
                                                        <telerik:RadButton ID="RadButton3" runat="server" ToggleType="Radio" ButtonType="ToggleButton"
                                                            GroupName="Radios" AutoPostBack="false" CausesValidation="false" Text="All" Checked="true">
                                                        </telerik:RadButton>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                        <div class="control-group">
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Primary Email  </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <asp:TextBox ID="txtEmail" runat="server" class="form-control" onkeypress="isPressEnter(event)" />
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Role </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <telerik:RadComboBox ID="ddlRole" runat="server" DataTextField="ROLE_NAME" DataValueField="ID" class="form-control"
                                                            Width="80%" Filter="StartsWith" MaxHeight="700px" />
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="clearfix"></div>
                                    </div>
                                </div>

                                <div class="popup-btn">
                                    <div class="col-md-12 btn-edit">
                                        <button id="btnSearch" type="button" class="btn btn-defaul" runat="server" onserverclick="btnSearch_ServerClick">
                                            <img src="../Images/search.png" style="width: 20px; height: 20px" />
                                            Search
                                        </button>
                                        <button class="btn btn-defaul" type="button" onclick="ClearClick();return false;">
                                            <img src="../Images/clear.png" style="width: 20px; height: 20px" />
                                            Clear
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="edit-form highlight">
                        <div class="control-group">
                            <h4>Users</h4>
                        </div>
                        <div class="col-md-12 combobox-email">
                            <div class="col-md-5 btn-edit">
                                <button id="btnAddUser" type="button" class="btn btn-defaul" runat="server" onserverclick="btnAddUser_ServerClick">
                                    <img src="../Images/add.png" style="width: 16px; height: 16px" />
                                    Add User
                                </button>
                                <button id="lbtnExportToCSV" type="button" runat="server" class="btn btn-defaul" onserverclick="lbtnExportToCSV_ServerClick">
                                    <img src="../Images/CSV.png" style="width: 16px; height: 16px;" />
                                    Export to Excel
                                </button>
                            </div>
                            <div class="col-md-4" style="vertical-align: central; padding-top: 6px; padding-bottom: 6px">
                                <label class="control-label" style="font-weight: 700">Email Template </label>
                            </div>
                            <div class="col-md-3" style="padding-right: 0; padding-bottom: 6px">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlEmailTemplate" runat="server" class="form-control" DataTextField="TEMPLATE_NAME" DataValueField="ID"
                                        Width="100%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div style="width: 100%">
                            <telerik:RadGrid ID="RadGrid1" ShowStatusBar="True" runat="server" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="True" OnPreRender="RadGrid1_PreRender"
                                OnItemDataBound="RadGrid1_ItemDataBound" AllowFilteringByColumn="false" AutoGenerateColumns="False" GridLines="None" Width="100%" OnNeedDataSource="RadGrid1_NeedDataSource"
                                Font-Size="12px" EnableLinqExpressions="false" OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand">
                                <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="false">
                                    <Selecting AllowRowSelect="false" />
                                    <ClientEvents OnRowMouseOver="RowMouseOver" />
                                </ClientSettings>
                                <MasterTableView PageSize="10" NoDetailRecordsText="No records" NoMasterRecordsText="No records" ShowHeader="true" DataKeyNames="UserID, ROLE_ID" ClientDataKeyNames="UserID" TableLayout="Fixed">
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="UserID" UniqueName="UserID" Display="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="ROLE_ID" UniqueName="ROLE_ID" Display="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridImageColumn UniqueName="GridImageColumn" DataType="System.String" DataImageUrlFields="IMAGE"
                                            AlternateText="TITLE" DataAlternateTextField="TITLE"
                                            ImageAlign="Middle" ImageHeight="80px" ImageWidth="80px" HeaderText="IMAGE">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="8.5%" />
                                        </telerik:GridImageColumn>
                                        <telerik:GridBoundColumn DataField="TITLE" HeaderText="Designation" UniqueName="TITLE" SortExpression="TITLE">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10.5%" />
                                           <ItemStyle Wrap="false" HorizontalAlign="left" Width="10%" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridTemplateColumn HeaderText="Primary Email" UniqueName="PRIMARY_EMAIL">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="15%" />
                                           <ItemStyle Wrap="false" HorizontalAlign="left" Width="15%" />
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lbtnSendEmail1" runat="server" Text='<%# Eval("PRIMARY_EMAIL") %>' OnClick="sendEmail_Click" ForeColor="Blue" />
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>

                                        <telerik:GridTemplateColumn HeaderText="Role" UniqueName="ROLE_NAME" DataField="RoleName" >
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="17%" />
                                           <ItemStyle Wrap="false" HorizontalAlign="center" Width="18%" />
                                            <FooterStyle HorizontalAlign="center" Width="18%" BackColor="LightBlue" Font-Bold="true" />
                                            <ItemTemplate>
                                                <telerik:RadComboBox ID="ddlRoleName" runat="server" DataTextField="ROLE_NAME" DataValueField="ID" AutoPostBack="true" OnClick="return ddlRoleNameConfirm();"
                                                    Width="100%" Filter="StartsWith" MaxHeight="700px" OnSelectedIndexChanged="ddlRoleName_SelectedIndexChanged" CausesValidation="false" />
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn DataField="ROLE_NAME" HeaderText="ROLE" UniqueName="ROLE_NAME_TO_EXPORT" Display="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="USER_NAME" HeaderText="User Name" UniqueName="USER_NAME" SortExpression="USER_NAME">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="16%" />
                                           <ItemStyle Wrap="false" HorizontalAlign="left" Width="15%" />
                                        </telerik:GridBoundColumn>

                                        <telerik:GridTemplateColumn DataField="ACTIVE" HeaderText="STATUS" UniqueName="ACTIVE">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" />
                                            <ItemStyle HorizontalAlign="center" Width="7%" />
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chbActive" runat="server" Checked='<%# Convert.ToBoolean(Eval("ACTIVE")) %>' AutoPostBack="true" OnCheckedChanged="chbActive_CheckedChanged" />
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn DataField="IS_ADMIN" HeaderText="Admin" UniqueName="IS_ADMIN">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" />
                                            <ItemStyle HorizontalAlign="center" Width="7%" />
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chbIsAdmin" runat="server" Checked='<%# Convert.ToBoolean(Eval("IS_ADMIN")) %>' AutoPostBack="true" OnCheckedChanged="chbIsAdmin_CheckedChanged" />
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>

                                        <telerik:GridBoundColumn DataField="PHONE_OFFICE" HeaderText="Office Phone" UniqueName="PHONE_OFFICE" SortExpression="PHONE_OFFICE">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10%" />
                                           <ItemStyle Wrap="false" HorizontalAlign="left" Width="10%" />
                                        </telerik:GridBoundColumn>

                                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Tools" UniqueName="TOOLS">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10%" />
                                            <ItemStyle HorizontalAlign="center" Width="10%" />
                                            <FooterStyle HorizontalAlign="center" Width="7%" BackColor="LightBlue" />
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lbtnEdit" runat="server" CommandName="Edit" ToolTip="Edit">
                                                    <image src="../Images/edit.png" style="width:18px;height:18px"/>
                                                </asp:LinkButton>
                                                &nbsp
                                                <asp:LinkButton ID="lbtnDelete" runat="server" ToolTip="Delete" CommandName="Delete" OnClientClick="return radConfirmDelete(this, 'Are you sure you want to delete this User ?');">
                                                    <image src="../Images/delete.png" style="width:18px;height:18px"/>
                                                </asp:LinkButton>
                                                <asp:LinkButton ID="LinkButton1" runat="server" ToolTip="Change Password" CommandName="ChangePassword" OnClientClick="return openRadwindow('ChangePassword.aspx?UserID=' ,'rwResetPassword');">
                                                    <image src="../Images/change_password.png" style="width:18px;height:18px"/>
                                                </asp:LinkButton>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                    </Columns>
                                    <PagerStyle PageSizes="5,10,20,50" PagerTextFormat="{4}<strong>{5}</strong> users matching your search criteria"
                                        PageSizeLabelText="Users per page:" AlwaysVisible="true" />
                                </MasterTableView>
                                <PagerStyle Mode="NumericPages"></PagerStyle>
                            </telerik:RadGrid>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
